package com.csjbot.blackgaga.feature.settings.charge_setting;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.csjbot.blackgaga.R;

/**
 * author : chenqi.
 * e_mail : 1650699704@163.com.
 * create_time : 09/11/2017.
 */

public class NewMessageBroadcastReceiver extends BroadcastReceiver {
    private static AlertDialog dialog = null;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("com.example.BROADCAST")) {
            if (dialog == null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                final View view = View.inflate(context.getApplicationContext(), R.layout.dialog_hint, null);
                TextView message = view.findViewById(R.id.tv_message);
                Button l = view.findViewById(R.id.button);
                message.setText(R.string.pow_to_low);
                builder.setView(view)
                        .setCancelable(false);
                dialog = builder.create();
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                dialog.show();
                l.setOnClickListener(v -> {
                    dialog.cancel();
                    dialog.dismiss();
                    dialog = null;
                });
            }
        }
    }
}
